<template>
	<div class="system-user-container layout-padding">
		<el-card shadow="hover" class="layout-padding-auto">
			<div class="system-user-search mb15">
				<el-input size="default" placeholder="请输入订单号" style="max-width: 180px" v-model="name"> </el-input>
				<el-button size="default" type="primary" class="ml10" @click="searchList">
					<el-icon>
						<ele-Search />
					</el-icon>
					查询
				</el-button>
			</div>
			<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
				<el-table-column type="index" label="序号" width="60" />
				<el-table-column prop="code" label="订单编号" show-overflow-tooltip></el-table-column>
				<el-table-column prop="title" label="问题描述" show-overflow-tooltip></el-table-column>
				<el-table-column prop="accountName" label="用户姓名" show-overflow-tooltip></el-table-column>
				<el-table-column prop="devicecode" label="设备编号" show-overflow-tooltip></el-table-column>
				<el-table-column prop="address" label="地址" show-overflow-tooltip></el-table-column>
				<el-table-column prop="status" label="订单状态" show-overflow-tooltip>
					<template #default="scope">
						<el-tag v-if="scope.row.status == 'applying'" type="danger">申请中</el-tag>
						<el-tag v-if="scope.row.status == 'dealing'" type="success">处理中</el-tag>
						<el-tag v-if="scope.row.status == 'dealed'" type="info">已处理</el-tag>
						<el-tag v-if="scope.row.status == 'closed'" type="info">已关闭</el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="createdAt" label="创建时间" show-overflow-tooltip></el-table-column>
				<el-table-column label="操作" width="130">
					<template #default="scope">
						<el-button size="small" text type="primary">派单</el-button>
						<el-button :disabled="scope.row.username === 'admin'" size="small" text type="primary" @click="onRowDel(scope.row)">取消</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				@size-change="onHandleSizeChange"
				@current-change="onHandleCurrentChange"
				class="mt15"
				:pager-count="5"
				:page-sizes="[10, 20, 30]"
				v-model:current-page="state.tableData.param.pageNum"
				background
				v-model:page-size="state.tableData.param.pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="state.tableData.total"
			>
			</el-pagination>
		</el-card>
		<!-- <orderDialog ref="orderDialogRef" @refresh="getTableData()" /> -->
		<!-- <orderEditDialog ref="orderEditDialogRef" @refresh="getTableData()" /> -->
	</div>
</template>

<script setup lang="ts" name="systemUser">
import { reactive, onMounted, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';

import { useOrder } from './order';
const orderStore = useOrder();

// 引入组件
// const orderDialog = defineAsyncComponent(() => import('/@/views/order/dialog.vue'));
// const orderEditDialog = defineAsyncComponent(() => import('/@/views/order/editDialog.vue'));
// 定义变量内容
// const orderDialogRef = ref();
// const orderEditDialogRef = ref();
const state = reactive({
	tableData: {
		data: [],
		total: 0,
		loading: false,
		param: {
			pageNum: 1,
			pageSize: 10,
		},
	},
});
const name = ref('');

// 初始化表格数据
const getTableData = () => {
	state.tableData.loading = true;
	orderStore
		.getOrderList(name.value, state.tableData.param.pageSize, state.tableData.param.pageNum)
		.then((res) => {
			console.log(res);
			// res.list.push({
			// 	id:1,
			// 	code:'ORDER202109010001',
			// 	title:'设备故障',
			// 	applyer:'张三',
			// 	devicecode:'DEVICE202109010001',
			// 	address:'上海市浦东新区',
			// 	status:'applying',
			// 	createdAt:'2021-09-01 12:00:00'
			// })
			// res.list.push({
			// 	id:1,
			// 	code:'ORDER202109010002',
			// 	title:'设备故障',
			// 	applyer:'lisi',
			// 	devicecode:'DEVICE202109010002',
			// 	address:'上海市浦东新区',
			// 	status:'dealing',
			// 	createdAt:'2021-09-01 12:00:00'
			// })
			// res.list.push({
			// 	id:1,
			// 	code:'ORDER202109010003',
			// 	title:'设备故障',
			// 	applyer:'MrgG',
			// 	devicecode:'DEVICE202109010003',
			// 	address:'上海市浦东新区',
			// 	status:'dealed',
			// 	createdAt:'2021-09-01 12:00:00'
			// })
			// res.list.push({
			// 	id:1,
			// 	code:'ORDER202109010004',
			// 	title:'设备故障',
			// 	applyer:'MrsZhang',
			// 	devicecode:'DEVICE202109010004',
			// 	address:'上海市浦东新区',
			// 	status:'closed',
			// 	createdAt:'2021-09-01 12:00:00'
			// })
			state.tableData.data = res.list;
			state.tableData.total = res.total;
			state.tableData.loading = false;
		})
		.catch((err) => {
			console.log(err);
			state.tableData.loading = false;
		});
};
// // 打开新增用户弹窗
// const onOpenAddOrder = (type: string) => {
// 	orderDialogRef.value.openDialog(type);
// };
// // 打开修改用户弹窗
// const onOpenEditOrder = (type: string, row: any) => {
// 	orderEditDialogRef.value.openDialog(type, row);
// };

// 删除用户
const onRowDel = (row: any) => {
	ElMessageBox.confirm(`此操作将删除厂家：“${row.name}”，是否继续?`, '提示', {
		confirmButtonText: '确认',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(() => {
			useOrder()
				.delete(row.id)
				.then(() => {
					getTableData();
					ElMessage.success('删除成功');
				})
				.catch((err) => {
					ElMessage.error(err.message);
				});
		})
		.catch(() => {});
};
// 分页改变
const onHandleSizeChange = (val: number) => {
	state.tableData.param.pageSize = val;
	getTableData();
};
const searchList = () => {
	state.tableData.param.pageNum = 1;
	getTableData();
};
// 分页改变
const onHandleCurrentChange = (val: number) => {
	state.tableData.param.pageNum = val;
	getTableData();
};
// 页面加载时
onMounted(() => {
	getTableData();
});
</script>

<style scoped lang="scss">
.system-user-container {
	:deep(.el-card__body) {
		display: flex;
		flex-direction: column;
		flex: 1;
		overflow: auto;
		.el-table {
			flex: 1;
		}
	}
}
</style>
./order
